﻿using System;
using System.Collections.Generic;
using System.Windows;
using SmartSpace.UI.Silverlight.Theme;

namespace Themes.WorkSpace
{
    public class WorkSpaceTheme : ITheme
    {
        private static string s_hostUrl;

        /// <summary>
        /// silverlight 所在的网站地址
        /// </summary>
        public static string HostUrl
        {
            get
            {
                if (string.IsNullOrEmpty(s_hostUrl))
                {
                    string sourcePath = Application.Current.Host.Source.AbsoluteUri.ToUpper();
                    string absolutePath = Application.Current.Host.Source.AbsolutePath.ToUpper();
                    if (absolutePath.StartsWith("/CLIENTBIN"))
                    {
                        s_hostUrl = sourcePath.Replace(absolutePath, "/");
                    }
                    else
                    {
                        // ex: /WebSite/ClientBin/DemeterSoft.Shell.xap
                        // 含有虚拟目录
                        string[] subs = absolutePath.Split(new string[] { "/CLIENTBIN" }, StringSplitOptions.RemoveEmptyEntries);
                        absolutePath = absolutePath.Replace(subs[0], string.Empty);
                        s_hostUrl = sourcePath.Replace(absolutePath, "/");
                    }
                }
                return s_hostUrl;
            }
        }

        private MainPanel m_mainPanel;

        #region ITheme Members

        public IMainPanel GetMainPanel()
        {
            if (m_mainPanel == null)
            {
                m_mainPanel = new MainPanel();
            }
            return m_mainPanel;
        }

        public IEnumerable<ResourceDictionary> GetResourceDictionaries()
        {
            List<ResourceDictionary> dictionaries = new List<ResourceDictionary>();

            ResourceDictionary resourceDictionary = new ResourceDictionary();
            Application.LoadComponent(resourceDictionary, new Uri("/Themes.WorkSpace;component/Styles/Window.xaml", UriKind.Relative));
            //Application.LoadComponent(resourceDictionary, new Uri("/Themes.WorkSpace;component/Styles/Button.xaml", UriKind.Relative));
            //Application.LoadComponent(resourceDictionary, new Uri("/Themes.WorkSpace;component/DictionaryForm.xaml", UriKind.Relative));
            //Application.LoadComponent(resourceDictionary, new Uri("/Themes.WorkSpace;component/DictionaryScrollViewer.xaml", UriKind.Relative));
            //Application.LoadComponent(resourceDictionary, new Uri("/Themes.WorkSpace;component/DictionaryCombox.xaml", UriKind.Relative));
            //Application.LoadComponent(resourceDictionary, new Uri("/Themes.WorkSpace;component/DictionaryDataGrid.xaml", UriKind.Relative));
            ////Application.LoadComponent(resourceDictionary, new Uri("/Themes.WorkSpace;component/DictionaryTextBox.xaml", UriKind.Relative));
            //Application.LoadComponent(resourceDictionary, new Uri("/Themes.WorkSpace;component/DictionaryBusyIndicator.xaml", UriKind.Relative));
            ////Application.LoadComponent(resourceDictionary, new Uri("/Themes.WorkSpace;component/DictionaryWindow.xaml", UriKind.Relative)); 
            dictionaries.Add(resourceDictionary);
            
            return dictionaries;
        }

        public string GetThemeID()
        {
            return "Themes.WorkSpace";
        }

        public string GetThemeName()
        {
            return "Themes WorkSpace主题";
        }

        #endregion
    }
}
